﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Resources;
using ClassLibrary;

namespace ControlLibrary
{
    public partial class CategoryItem : UserControl
    {
        private Color _selectionBackColor = Color.LightGray;

        public int ContentWidth
        {
            get
            {
                return checkBox1.Size.Width;
            }
        }
        public int HighlightWidth
        {
            set { panel_HighLight.Width = value; }
        }
        public string Title
        { 
            get { return checkBox1.Text; }
            set { checkBox1.Text = value; }
        }
        public bool Check
        {
            set { checkBox1.Checked = value; }
            get { return checkBox1.Checked; }
        }
        public bool various;

        public delegate void OnCheckChanged();
        [Category("Configuration"), Browsable(true), Description("")]
        public event OnCheckChanged onCheckChanged;

        #region CONSTRUCTORS

        public CategoryItem(string title)
        {
            InitializeComponent();
            checkBox1.Text = title;
            checkBox1.AutoSize = true;
            checkBox1.Refresh();
            panel_HighLight.Width = ContentWidth;
        }

        public CategoryItem()
        {
            InitializeComponent();
            checkBox1.AutoSize = true;
            checkBox1.Refresh();
            panel_HighLight.Width = ContentWidth;
        }

        #endregion

        #region UI

        private void enter()
        {
            this.Cursor = Cursors.Hand;

            checkBox1.BackColor = _selectionBackColor;
            panel_HighLight.BackColor = _selectionBackColor;
        }

        private void leave()
        {
            this.Cursor = Cursors.Default;

            checkBox1.BackColor = Color.White;            
            panel_HighLight.BackColor = Color.White;
        }

        private void checkBox1_MouseEnter(object sender, EventArgs e)
        {
            enter();
        }

        private void checkBox1_MouseLeave(object sender, EventArgs e)
        {
            leave();
        }

        private void panel_HighLight_MouseEnter(object sender, EventArgs e)
        {
            enter();
        }

        private void panel_HighLight_MouseLeave(object sender, EventArgs e)
        {
            leave();
        }

        private void CategorieListItem_MouseEnter(object sender, EventArgs e)
        {
            enter();
        }

        private void CategorieListItem_MouseLeave(object sender, EventArgs e)
        {
            leave();
        }

        #endregion

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (null != onCheckChanged)
                onCheckChanged();
        }
    }
}
